package com.loukou.lkt.lkt.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.loukou.lkt.lkt.entity.GoodsCost;

public interface GoodsCostDao extends CrudRepository<GoodsCost,Integer>{

	@Query(value = "select  * from lkt_goods_cost  where goods_id = ?1 order by  create_time  desc limit 1", nativeQuery = true)
	GoodsCost getGoodsCost(int goodsId);
	
	List<GoodsCost> findByGoodsId(int goodsId);
	
	@Query(value = "select id,group_concat(distinct goods_id order by create_time DESC) as goods_id, substring_index(group_concat(cost_price order by create_time DESC),',',1) as cost_price, substring_index(group_concat(create_time order by create_time DESC),',',1) as create_time from lkt_goods_cost where goods_id in (?1) group by goods_id", nativeQuery = true)
	List<GoodsCost> getGoodsCosts(String goodsId);	
	
	List<GoodsCost> findByGoodsIdIn(List<Integer> goodsIds);
	
}
